package com.loveprogrammer.base.bean.session;

import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName Session
 * @Description 用户session
 * @Author admin
 * @Date 2024/2/4 17:25
 * @Version 1.0
 */
public class Session {

    private static final Logger logger = LoggerFactory.getLogger(Session.class);

    /**
     * sessionId
     */
    private int id;

    /**
     * 房间id，PVP 或者团队副本的时候使用
     */
    private int roomId;

    /**
     * 用户
     */
    private String userId;

    /**
     * 用户昵称
     */
    private String nickname;

    /***
     * 绑定的channel
     */
    private Channel channel;

    public Session(int id,Channel channel) {
        this.id = id;
        this.channel = channel;
    }

    /**
     * 关闭与客户端的连接
     */
    public void close() {
        if (channel == null) {
            return;
        }
        try {
            if (channel.isActive() || channel.isOpen()) {
                channel.close().sync();
            }
        } catch (InterruptedException e) {
            logger.error("channel.close find error ", e);
        }

    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Channel getChannel() {
        return channel;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }
}
